import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/manager/xindong_audio_ctr.dart';
import 'package:xindong/models/user/xindong_kongjian_user.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/routes/userspace/xindong_kongjian_ctr.dart';
import 'package:xindong/utils/xindong_image_util.dart';

class XinDongKongJianHeader extends StatelessWidget {
  final XinDongSpaceUser model;

  const XinDongKongJianHeader({super.key, required this.model});

  @override
  Widget build(BuildContext context) {
    final dataList = model.photo_show;
    final online = XinDongKongJianCtr.to.userspace?.is_online == 1;
    // final dataList = model.photo_show..insert(0, model.head_portrait ?? '');
    return Container(
      width: screenWidth,
      height: screenWidth,
      color: Colors.orange,
      child: Stack(
        children: [
          Swiper(
            autoplay: dataList.length > 1,
            loop: dataList.length > 1,
            itemCount: dataList.length,
            itemBuilder: (BuildContext context, int index) {
              return ImageUtil.networkImageUrl(dataList[index]);
            },
          ),

          // 顶部渐变
          Positioned.fill(
            child: Container(
              height: 88,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  colors: [
                    DZColors.hexColor(0x000000, alpha: 0.43),
                    DZColors.hexColor(0x131313, alpha: 0),
                    DZColors.hexColor(0x171717, alpha: 0),
                    DZColors.hexColor(0x000000, alpha: 0.65),
                  ],
                ),
              ),
            ),
          ),

          // 顶部渐变
          Positioned(
            bottom: 28,
            left: 16,
            child: Container(
              height: 23,
              padding: const EdgeInsets.only(left: 9, right: 9),
              decoration: BoxDecoration(color: Colors.white.withOpacity(0.5), borderRadius: BorderRadius.circular(30)),
              child: Row(
                children: [
                  ImageUtil.asset(online ? AssetsRes.ICON_ONLINE : AssetsRes.ICON_OFFLINE, width: 8),
                  Text(
                    " ${online ? "${model.isMale ? "他" : "她"}正在线" : "已离线"}",
                    style: const TextStyle(color: DZColors.titleColor, fontSize: 12, height: 1.2),
                  ),
                ],
              ),
            ),
          ),

          // 关注数
          Positioned(
            bottom: 28,
            right: 16,
            child: GetBuilder<XinDongKongJianCtr>(
              id: XinDongKongJianCtr.updateIdLoadingInfo,
              builder: (controller) {
                return Container(
                  height: 23,
                  alignment: Alignment.center,
                  padding: const EdgeInsets.only(left: 15, right: 15),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(28),
                    border: Border.all(color: Colors.white, width: 0.5),
                  ),
                  child: Row(
                    children: [
                      Text(
                        "${controller.userspace?.attention}人关注",
                        style: const TextStyle(fontSize: 12, color: Colors.white, height: 1.2),
                      ),
                    ],
                  ),
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}
